$(function(){
    var enbs =  $("input:checkbox");
    $(".datepicker").datepicker();
    $.each(enbs,function(i,chk){
        $(chk).attr("checked",false);
        toggleDisabled(chk);
    });  
    fillDepartments("deptlist");
});


function dataSubmit(self) {
	var form = $(self).parent().parent().parent();
	var data = form.serialize();
	var url='contract/contract!query';
	doPost(url,data);
}


function statAll(self){	
	var form = $(self).parent().parent().parent();
	var data = form.serialize();
	var url='contract/contract!query';
	doPost(url,data);
}

function collectAll(self){
	var form = $(self).parent().parent().parent();
	var data = form.serialize();
	var url='contract/contract!collect';
	doPost(url,data);
}

function toggleDisabled(self){
	var chk = $(self).attr("checked");
    var sbs = $(self).siblings() ;
	if(!chk){
    	$.each(sbs,function(i,item){
    		$(item).attr("disabled",true);
    		$(item).attr("enabled",false);
    	});
    }else{
    	$.each(sbs,function(i,item){
    		$(item).attr("disabled",false);
    		$(item).attr("enabled",true);
    	});
    }
}
function fillDepartments(deptId) {
	var depts = $("#"+deptId);
	$.getJSON('admin/department/department!bytype',
			{
		      "bean.id":"root",
		      "bean.departmentType":"Manufacture"		
			},
			
		function(data, textStatus, jqXHR) {

		$.each(data, function(i, item) {
			var ipt = $("<option value='"+item['id']+"'>"+item['name']+"</option>");			
			depts.append(ipt);			
		});	
		
	});
}